'use strict';

const bluebird = require('bluebird')
const _ = require('lodash')
const AWS = require('aws-sdk')
const request = require('request-promise')
const url = require('url')
const uuid = require('uuid/v4')
const path = require('path')

const config = require('../config')



/**
 * Config
 */
const {
    publicBucket,
    privateBucket
} = config.aws

const {
    accessKeyId,
    secretAccessKey
} = config.aws.s3

AWS.config.setPromisesDependency(bluebird)
AWS.config.update({ accessKeyId, secretAccessKey })
AWS.config.region = config.aws.region || 'cn-north-1'


/**
 * AWS Service
 */
const S3 = new AWS.S3({ computeChecksums: true })


exports.S3 = S3



exports.put = function(Body, Key, ContentType, privated = false) {
    const params = Object.assign({ Key, Body }, privated ? privateBucket : publicBucket)
    params.ContentType = ContentType
    return S3.upload(params).promise()
}